#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include "errsys.h"

double jsqrt(double v)
{
	double l=0.0, h=v;
	double d,m, mini = 0.000001;

	for(;;){
		m = (l+h)/2;
		d = m*m-v;

		if(d>mini)
			h=m;
		else if(d<-mini)
			l=m;
		else 
			return m;
	}
}

int is_primer(unsigned long v)
{
	if(v==1)
		return 0;
	if(v==2)
		return 1;

	int sqrt = (int)jsqrt((double)v)+1;
	int i;

	for(i=2;i<=sqrt;++i)
		if(v%i == 0)
			return 0;

	return 1;
}

int main(int argc, char **argv)
{
	if(argc==1){
		printf("Usage:%s interger\n",argv[0]);
		exit(1);
	}

	int i = atoi(argv[1]);
//	printf("%f\n",jsqrt(i));
	
	int count = 0;
	for(;count<100;++i){
		if(is_primer(i)){
			printf("%10d ",i);
			++count;
			if(count%5==0)
				printf("\n");
		}
	}

	return 0;
}

